package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/x/errors"
	"go-exp/exp-test/httx-ext/internal/svc"
	"go-exp/exp-test/httx-ext/internal/types"
)

type LoginLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *LoginLogic) Login(req *types.LoginRequest) (resp *types.LoginResponse, err error) {
	// 模拟登录逻辑
	if req.Username != "go-zero" || req.Password != "123456" {
		return nil, errors.New(1001, "用户名或密码错误")
	}

	resp = new(types.LoginResponse)
	resp.Name = "go-zero"
	resp.UID = 1
	return resp, nil
}
